using UnityEngine;

public class ProductVehicleUpgrade : Product
{
	[Header("Upgrade params")]
	public int upgradeNumber;

	public string targetId;

	public ProductVehicleType targetType;

	public UpgradeType upgradeType;

	public float coef;

	public override bool equippable
	{
		get
		{
			return false;
		}
	}

	public ProductVehicleUpgrade(string id_G, MoneyType priceIng_G, int price_G, bool availableForBuy_G, float sortWeight_G, string texture_G, string nameForFlurry_G, bool isTemporary_G, int tier_G, bool bestPrice_G, bool newProduct_G, string nextProductId_G, string prevProductId_G, string categoryName_G, string subCategoryName_G, RareType rare_G, int upgradeNumber_G, string targetId_G, ProductVehicleType targetType_G, UpgradeType upgradeType_G, float coef_G)
		: base(id_G, priceIng_G, price_G, availableForBuy_G, sortWeight_G, texture_G, nameForFlurry_G, isTemporary_G, tier_G, bestPrice_G, newProduct_G, nextProductId_G, prevProductId_G, categoryName_G, subCategoryName_G, rare_G)
	{
		upgradeNumber = upgradeNumber_G;
		targetId = targetId_G;
		targetType = targetType_G;
		upgradeType = upgradeType_G;
		coef = coef_G;
	}

	public override void BuyProduct(params object[] args)
	{
		base.BuyProduct(args);
		ProductFreeUpgrade vehicleFreeUpgrade = MarketController.Instance.GetVehicleFreeUpgrade(this);
		if (vehicleFreeUpgrade != null && vehicleFreeUpgrade.Count > 0)
		{
			string key = vehicleFreeUpgrade.KeyForStorage();
			MarketController.SaveFreeVehicleUpgradesCount(-1, vehicleFreeUpgrade.maxCount, key);
		}
		if (MarketControllerUI.instance != null)
		{
			bool flag = false;
			ProductVehicleType productVehicleType = targetType;
			if (productVehicleType == ProductVehicleType.Titan)
			{
				if (MarketControllerUI.instance.productsPanel.productMiniInfoPanel.titanMiniInfoPanel.gameObject.activeInHierarchy)
				{
					MarketControllerUI.instance.productsPanel.productMiniInfoPanel.titanMiniInfoPanel.SetInfo(((nextProduct != null) ? nextProduct : this) as ProductVehicleUpgrade);
				}
			}
			else if (MarketControllerUI.instance.productsPanel.productMiniInfoPanel.carMiniInfoPanel.gameObject.activeInHierarchy)
			{
				MarketControllerUI.instance.productsPanel.productMiniInfoPanel.carMiniInfoPanel.SetInfo(((nextProduct != null) ? nextProduct : this) as ProductVehicleUpgrade);
			}
		}
		if (targetType != ProductVehicleType.Titan && Load.LoadString("car") != targetId)
		{
			MarketController.Instance.Equip(MarketController.Instance.GetProduct(targetId));
		}
	}

	public int FirstNotBuyedOrLastUpgradeNumber()
	{
		Product product = this;
		while (product.prevProduct != null)
		{
			product = product.prevProduct;
		}
		int num = 0;
		while (product.nextProduct != null && product.Purchased)
		{
			product = product.nextProduct;
			num++;
		}
		return num;
	}
}
